package com.java1412;

/**
 * @author java1412
 * @create 2022-09-21 17:11
 */
public class Test4 {
    public static void main(String[] args) {
        RunThread runThread = new RunThread();
        Thread t1 = new Thread(runThread, "1号选手");
        Thread t2 = new Thread(runThread, "2号选手");
        Thread t3 = new Thread(runThread, "3号选手");
        t1.start();
        t2.start();
        t3.start();
    }
}

class RunThread implements Runnable {
    @Override
    public synchronized void run() {
        System.out.println(Thread.currentThread().getName() + "拿到接力棒!");
        for (int i = 1; i <= 10; i++) {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "跑了" + (i * 10) + "米!");
        }
    }
}
